<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1. 正整数和负整数的最大计数
        // 二分查找开区间
        const searchRanage = function (nums, target) {
            // 开区间，left初始化为-1，right初始化为nums.length
            let left = -1;
            let right = nums.length
            let mid;
            // 开区间，这里写left + 1 < right
            while (left + 1< right) {
                mid = left + ((right - left) >> 1)
                if (nums[mid] >= target) {
                    // 是mid，而不是mid-1
                    right = mid
                } else {
                    // 是mid，而不是mid+1
                    left = mid
                }
            }
            // 注意开区间返回的是right
            return right
        }
        var maximumCount = function(nums) {
            let neg = searchRanage(nums, 0)
            let pos = nums.length - searchRanage(nums, 1)
            return Math.max(neg, pos)
        };
        console.log(maximumCount([-2,-1,-1,1,2,3]), 'maximumCount');
        // console.log(maximumCount([-3,-2,-1,0,0,1,2]), 'maximumCount');
        // console.log(maximumCount([5,20,66,1314]), 'maximumCount');
        
    </script>
</body>

</html>